package com.tsingteng.cosfun.ui.setting.presenter;

import com.tsingteng.cosfun.bean.ProfileAdressBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.setting.contract.ProfileAdress;
import com.tsingteng.cosfun.ui.setting.imodel.ProFileAdressModel;

public class ProfileAdressPresenter extends BasePresenter<ProfileAdress.IProfileView> implements ProfileAdress.IProfilePresenter{

    private ProFileAdressModel proFileAdressModel;
    private ProfileAdress.IProfileView profileView;
    public ProfileAdressPresenter(){
        this.proFileAdressModel=new ProFileAdressModel();
    }
    @Override
    public void saveReceiceAddress(String userName, String mobilePhone, String region, String adress) {
         profileView=getView();
        RxObserver<ProfileAdressBean> rxObserver=new RxObserver<ProfileAdressBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                profileView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(ProfileAdressBean profileAdressBean) {
                 profileView.showProfileAdress();
            }
        };
        proFileAdressModel.addProfileAdress(userName,mobilePhone,region,adress,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void updateReceiceAddress(long id, String userName, String mobilePhone, String region, String adress) {
        profileView=getView();
        RxObserver<ProfileAdressBean> rxObserver=new RxObserver<ProfileAdressBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                profileView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(ProfileAdressBean profileAdressBean) {
                profileView.showProfileAdress();
            }
        };
        proFileAdressModel.changeProfileAdress(id,userName,mobilePhone,region,adress,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getReceiveAddress() {
        profileView = getView();
        RxObserver<ProfileAdressBean> rxObserver = new RxObserver<ProfileAdressBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                profileView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(ProfileAdressBean profileAdressBean) {
                 profileView.showReceiveAddress(profileAdressBean);
            }
        };
        proFileAdressModel.getProfileAdress(rxObserver);
        addDisposable(rxObserver);
    }
}
